package com.ecr.hub.front.validator;

import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

public class SelectPositionRequiredValidator extends AbstractGenericValidator {

	@Override
	public boolean executeValidator(FacesContext arg0, UIComponent arg1,
			Object arg2) throws Exception {

		// On teste "", >=0.
		try {
			// Teste ""
			if (arg2.toString().trim().isEmpty()) {
				return false;
			} else {
				try {
					return (Integer.valueOf(arg2.toString()) >= 0);
				} catch (Exception e) {
					// C'est une valeur string et remplie.
					return true;
				}
			}
		} catch (Exception e) {
			// Teste null
			return false;
		}
	}

	@Override
	protected String[] getAttributsList() {
		return new String[] { AbstractValidator.FIELD_NAME };
	}

	@Override
	protected String getMessageKey() {
		return "validator.select.required";
	}

	@Override
	protected Severity getSeverityLevel() {
		return FacesMessage.SEVERITY_ERROR;
	}
}
